<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>管理员后台 - 商品评价系统</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
    <link rel="stylesheet" href="${ctx}/static/css/common.css">
    <link rel="stylesheet" href="${ctx}/static/css/admin.css">

    <style>
        body {
            font-family: 'Microsoft YaHei', Arial, sans-serif;
            margin: 0;
            padding: 0;
            background-color: #f5f5f5;
        }
        .header {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            padding: 20px 0;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        }
        .header-content {
            max-width: 1200px;
            margin: 0 auto;
            padding: 0 20px;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }
        .logo {
            font-size: 24px;
            font-weight: bold;
        }
        .user-info {
            display: flex;
            align-items: center;
            gap: 15px;
        }
        .container {
            max-width: 1200px;
            margin: 30px auto;
            padding: 0 20px;
        }
        .dashboard-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
            gap: 20px;
            margin-bottom: 30px;
        }
        .card {
            background: white;
            padding: 30px;
            border-radius: 10px;
            box-shadow: 0 5px 15px rgba(0,0,0,0.1);
            text-align: center;
            transition: transform 0.3s ease;
        }
        .card:hover {
            transform: translateY(-5px);
        }
        .card h3 {
            color: #333;
            margin-bottom: 15px;
            font-size: 20px;
        }
        .card p {
            color: #666;
            margin-bottom: 20px;
            line-height: 1.6;
        }
        .btn {
            display: inline-block;
            padding: 12px 25px;
            background: linear-gradient(45deg, #667eea, #764ba2);
            color: white;
            text-decoration: none;
            border-radius: 25px;
            transition: all 0.3s ease;
            font-weight: 500;
        }
        .btn:hover {
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(0,0,0,0.2);
        }
        .logout-btn {
            background: #e74c3c;
            padding: 8px 15px;
            border-radius: 20px;
            text-decoration: none;
            color: white;
            transition: background 0.3s ease;
        }
        .logout-btn:hover {
            background: #c0392b;
        }
    </style>
</head>
<body>
    <div class="header">
        <div class="header-content">
            <div class="logo">商品评价系统 - 管理员控制台</div>
            <div class="user-info">
                <span>欢迎，管理员</span>
                <a href="#" onclick="logout()" class="logout-btn">退出登录</a>
            </div>
        </div>
    </div>

    <div class="container">
        <div class="dashboard-grid">
            <div class="card">
                <h3>用户管理</h3>
                <p>管理系统用户，查看用户信息，处理用户相关事务</p>
                <a href="${ctx}/page/admin/users" class="btn">进入用户管理</a>
            </div>
            
            <div class="card">
                <h3>商品管理</h3>
                <p>管理商品信息，添加、编辑、删除商品</p>
                <a href="${ctx}/page/admin/products" class="btn">进入商品管理</a>
            </div>
            
            <div class="card">
                <h3>评价管理</h3>
                <p>管理用户评价，审核评价内容，处理不当评价</p>
                <a href="${ctx}/page/admin/reviews" class="btn">进入评价管理</a>
            </div>
            
<%--            <div class="card">--%>
<%--                <h3>系统统计</h3>--%>
<%--                <p>查看系统运行数据，用户活跃度，商品销售统计</p>--%>
<%--                <a href="#" onclick="viewStats()" class="btn">查看统计数据</a>--%>
<%--            </div>--%>
        </div>
        
        <div class="card">
            <h3>快速操作</h3>
            <p>常用管理功能快速入口</p>
            <div style="display: flex; gap: 15px; justify-content: center; flex-wrap: wrap; margin-top: 20px;">
                <a href="${ctx}/page/products" class="btn">查看所有商品</a>
                <a href="${ctx}/page/admin/reviews" class="btn">待审核评价</a>
                <a href="${ctx}/page/admin/users" class="btn">用户列表</a>
            </div>
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script>
        // 设置上下文路径
        window.CONTEXT_PATH = '${ctx}';
    </script>
    <script src="${ctx}/static/js/config.js"></script>
    <script src="${ctx}/static/js/common.js"></script>
    <script>
        
        $(document).ready(function() {
            // 检查管理员权限
            checkAdminPermission();
        });
        
        function checkAdminPermission() {
            apiRequest({
                url: AppConfig.APIS.USER.CURRENT,
                type: 'GET',
                success: function(response) {
                    if (response.success && response.data) {
                        if (response.data.role !== 'ADMIN') {
                            alert('权限不足，请使用管理员账号登录');
                            window.history.back(); // 返回上一页
                        }
                    } else {
                        goToPage(AppConfig.PAGES.LOGIN);
                    }
                },
                error: function() {
                    goToPage(AppConfig.PAGES.LOGIN);
                }
            });
        }
        
        function logout() {
            apiRequest({
                url: AppConfig.APIS.USER.LOGOUT,
                type: 'POST',
                success: function(response) {
                    if (response.success) {
                        goToPage(AppConfig.PAGES.INDEX);
                    }
                }
            });
        }
        
        function viewStats() {
            // 可以跳转到统计页面或显示统计模态框
            goToPage(AppConfig.PAGES.ADMIN_DASHBOARD);
        }
    </script>
</body>
</html>